package com.oa.controller;

import com.oa.pojo.Back;
import com.oa.pojo.Evection;
import com.oa.pojo.Result;
import com.oa.service.EvectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "出差：在线接口")
@RestController
@RequestMapping("/evection")
public class EvectionController {
    @Autowired
    private EvectionService evectionService;

    @CrossOrigin
    @ApiOperation(value = "根据指定id 查询出差信息",httpMethod = "GET")
    @GetMapping("/selectAllByIdEvcation")
    public Result selectAllByIdEvcation(Integer id){
        System.out.println("执行出差信息查询");
      Evection evection = new Evection();
      evection.setId(id);
        List<Evection> evectionList = new ArrayList<>();
        evectionList=evectionService.selectAllByIdEvcation(evection);
        if(evectionList!=null){
            return Result.success(evectionList);
        }else {
            return Result.error("结果为空");
        }
    }


    @CrossOrigin
    @ApiOperation(value="出差信息更改",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/updateEvection")
    public Result updateEvection(@RequestBody Evection evection){
        System.out.println("执行修改出差信息");
        int flag=evectionService.updateEvection(evection);
        if(flag==1){
            return Result.success();
        }else if (flag==-1){
            return Result.error("-1");
        }else if (flag==-2){
            return Result.error("-2");
        }else if (flag==-3){
            return Result.error("-3");
        }else {
            return Result.error("0");
        }
    }

    @CrossOrigin
    @ApiOperation(value="添加：出差信息",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/insertEvection")
    public Result insertEvection(@RequestBody Evection evection){
        System.out.println("执行添加出差信息");
        int flag=evectionService.insertEvection(evection);
        if(flag==1){
            return Result.success();
        }else if (flag==-1){
            return Result.error("失败");
        }else {
            return Result.error("0");
        }
    }

    @CrossOrigin
    @ApiOperation(value="删除出差信息",httpMethod = "GET",notes = "返回的result类型json格式")
    @GetMapping("/deleteEvection")
    public  Result deleteEvection(Integer id){
        evectionService.deleteEvection(id);
        return Result.success();
    }
}
